package com.notepad;

import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.coobee.boot.Application;
import com.coobee.fx.support.AbstractApplication;
import com.coobee.fx.support.Display;
import com.coobee.fx.support.Window;
import com.notepad.enums.Images;
import com.notepad.page.MainPage;
import com.notepad.page.PopupMenu;

import javafx.stage.Stage;

/**
 * 服务器启动
 * 
 * @author 618lf
 */
@SpringBootApplication
public class NotepadApp {

	/**
	 * 启动界面
	 *   
	 * @author 618lf
	 */
	public static class UILauncher extends AbstractApplication {

		@Override
		protected CompletableFuture<Void> doStart(String[] args) {
			return this.execute(() -> {
				NotepadApp.startServer(args);
			});
		}

		@Override
		protected CompletableFuture<Void> doStop() {
			return this.execute(() -> {
				NotepadApp.stopServer();
			});
		}

		@Override
		protected Supplier<Window> customTrayWindow() {
			return () -> {
				return this.NewWindow(PopupMenu.class);
			};
		}

		@Override
		protected void customStage(final Stage stage) {
			stage.setTitle("Notepad");
			stage.getIcons().add(Display.loadImage(Images.Logo.images[0]));
		}
	}

	/**
	 * 启动服务
	 * 
	 * @param args
	 */
	static void startServer(String[] args) {
		Application.run(NotepadApp.class, args);
	}

	/**
	 * 启动服务
	 * 
	 * @param args
	 */
	static void stopServer() {
		Application.stop();
	}

	/**
	 * 主类
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		UILauncher.launch(UILauncher.class, MainPage.class, args);
	}
}